import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:flutter/material.dart";

class TapText extends StatelessWidget {
  final Widget? prefix;
  final IconData? suffixIcon;
  final TextStyle style;
  final String text;
  final void Function()? onTap;

  TapText({
    super.key,
    this.prefix,
    this.suffixIcon,
    TextStyle? style,
    required this.text,
    this.onTap,
  }) : style = const TextStyle(color: ThemeVars.colorPrimary)
            .merge(style)
            .copyWith(color: onTap == null ? ThemeVars.colorDisabled : null);

  @override
  Widget build(BuildContext context) {
    Widget current = Text(text, style: style);
    if (prefix != null || suffixIcon != null) {
      current = Row(
        children: [
          if (prefix != null) ...[prefix!, const SizedBox(width: 4)],
          current,
          if (suffixIcon != null) Icon(suffixIcon!, color: style.color),
        ],
      );
    }
    if (onTap != null) current = GestureDetector(onTap: onTap, child: current);
    return current;
  }
}
